/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.direction.hold;

import java.util.Calendar;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;
import app.base.Test;
import appscrn.ScnAty;
import cn.cheln.explorer.config.Constants;
import cn.cheln.support.data.text.xml.SPUtil;

import com.direction.hold.ui.SlideActivity;
import com.umeng.analytics.MobclickAgent;
import com.umeng.update.UmengUpdateAgent;

/**
 * 
 * @author Administrator
 */
public class VPAty extends ScnAty{

	public static SlideActivity slideActivity;
	public static boolean created = false;
	public static VPAty activity;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle icicle) {
		getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		try {
				slideActivity = new SlideActivity(this);
				slideActivity.preCreate(this);
				super.onCreate(icicle);
				Test.showDensity(this);
				handler.sendEmptyMessageDelayed(0, 900);
				slideActivity.setEntryActivity(this);
				slideActivity.setSwipCapability(this);
				slideActivity.setSwipTitle(this);
				slideActivity.postCreate(icicle);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	Handler handler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			MobclickAgent.onError(VPAty.this);
			UmengUpdateAgent.setUpdateOnlyWifi(false);
			Long period = ((Long) SPUtil.getValue(VPAty.this,
					Constants.SharedPrefernce.File, "ftime", Long.class));
			if (period == -1 || period == null) {
				SPUtil.putValue(VPAty.this,
						Constants.SharedPrefernce.File, "ftime", Calendar
								.getInstance().getTimeInMillis());
			}

//			Logs.e("System.currentTimeMillis() - period "
//					+ (System.currentTimeMillis() - period) + " "
//					+ ((System.currentTimeMillis() - period) - 1000 * 60));
			if ((System.currentTimeMillis() - period) > 1000 * 60 * 60 * 24 * 7) {
				// Logs.e("System.currentTimeMillis() - period "+(System.currentTimeMillis()
				// - period));
				UmengUpdateAgent.update(VPAty.this);
				SPUtil.putValue(VPAty.this,
						Constants.SharedPrefernce.File, "ftime",
						System.currentTimeMillis());
			}
		}

	};

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onDestroy() {
		slideActivity.onEventDestroy();
		super.onDestroy();
	}

	// @Override
	// public void onAttachedToWindow() {
	// this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	// super.onAttachedToWindow();
	// }

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(this);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(this);
		activity = this;
	}

}
